package api_day03;

import java.util.ArrayList;

/*
    集合课堂练习
 */
public class ArrayListDemo {
    public static void main(String[] args) {
        ArrayList arr = new ArrayList();
        arr.add("str");
        arr.add("hello");
        arr.add("hi");
        arr.add("colletor");
        arr.add("iterator");
        Boolean test1 = listTest(arr,"str");
        System.out.println(test1);
        Boolean test2 = listTest(arr);
        System.out.println(test2);
        ArrayList<Integer> arr1 = listTest(new int[]{1,2,3,4,5});
        System.out.println(arr1);
        ArrayList<String> arr2 = new ArrayList<>();
        arr2.add("a");
        arr2.add("a");
        arr2.add("b");
        arr2.add("b");
        arr2.add("c");
        System.out.println("a:" + listCnt(arr2, "a"));
        System.out.println("b:" + listCnt(arr2, "b"));
        System.out.println("c:" + listCnt(arr2, "c"));
        System.out.println("xxx:" + listCnt(arr2, "xxx"));
    }

    private static int listCnt(ArrayList<String> arrayList, String string) {
        int cnt = 0;
        for (String str : arrayList) {
            if (str.equals(string)) cnt++;
        }
        return cnt;
    }

    private static ArrayList<Integer> listTest(int[] ints) {
        ArrayList<Integer> arr = new ArrayList<>();
        for (int a : ints){
            arr.add(a);
        }
        return arr;
    }

    private static Boolean listTest(ArrayList arr) {
        return arr.isEmpty();
    }

    private static Boolean listTest(ArrayList arr, String str) {
        return arr.contains(str);
    }
}
